package com.estate.web.controller.report.home;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.estate.common.core.controller.BaseController;
import com.estate.common.core.domain.AjaxResult;
import com.estate.common.core.domain.entity.SysUser;
import com.estate.system.domain.vo.HomeSaleDataView;
import com.estate.system.mapper.SysUserMapper;
import com.estate.system.service.impl.DataEnquiriesServiceImpl;
import com.estate.system.service.impl.DataListingsServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/home/businessDeveloper")
public class HomeBussinessDeveloperController extends BaseController {

    @Resource
    private DataEnquiriesServiceImpl dataEnquiriesServiceImpl;
    @Resource
    private SysUserMapper userMapper;
    @Resource
    private DataListingsServiceImpl dataListingsServiceImpl;

    @GetMapping("/getNewLandlords")
    public AjaxResult getNewLandlords(Map<String, Object> paramData) {
        Map<String, Object> result = new HashMap<>();
        result.put("newLandlords", 2137);
        result.put("upOrDown", "2.8%");
        return AjaxResult.success("success", result);
    }

    @GetMapping("/getNewListings")
    public AjaxResult getNewListings(Map<String, Object> paramData) {
        Map<String, Object> result = new HashMap<>();
        result.put("newListings", 5839);
        result.put("upOrDown", "2.6%");
        return AjaxResult.success("success", result);
    }

    @GetMapping("/getSignedLandlords")
    public AjaxResult getSignedLandlords(Map<String, Object> paramData) {
        Map<String, Object> result = new HashMap<>();
        result.put("upcomingTasks", 7138);
        result.put("upOrDown", "-1.3%");
        return AjaxResult.success("success", result);
    }
    @GetMapping("/getRankingOfNewListing")
    public AjaxResult getRankingOfNewListing(Map<String, Object> paramData) {
        Map<Integer, Map<String, Object>> areaRankings = new HashMap<>();

        Map<String, Object> data1 = new HashMap<>();
        data1.put("area", "Sydney CBD"); // 替换区域名
        data1.put("value", 3500); // 替换数值
        areaRankings.put(1, data1);

        Map<String, Object> data2 = new HashMap<>();
        data2.put("area", "North Sydney"); // 替换区域名
        data2.put("value", 3200); // 替换数值
        areaRankings.put(2, data2);

        Map<String, Object> data3 = new HashMap<>();
        data3.put("area", "Parramatta"); // 替换区域名
        data3.put("value", 2900); // 替换数值
        areaRankings.put(3, data3);

        Map<String, Object> data4 = new HashMap<>();
        data4.put("area", "Burwood"); // 替换区域名
        data4.put("value", 2800); // 替换数值
        areaRankings.put(4, data4);

        Map<String, Object> data5 = new HashMap<>();
        data5.put("area", "Rhodes"); // 替换区域名
        data5.put("value", 2600); // 替换数值
        areaRankings.put(5, data5);

        Map<String, Object> data6 = new HashMap<>();
        data6.put("area", "Wolli Creek"); // 替换区域名
        data6.put("value", 2400); // 替换数值
        areaRankings.put(6, data6);

        return AjaxResult.success("success", areaRankings);
    }

    @GetMapping("/getRankingOfTransactionsNumber")
    public AjaxResult getRankingOfTransactionsNumber(Map<String, Object> paramData) {
        Map<Integer, Map<String, Object>> areaRankings = new HashMap<>();
        Map<String, Object> data1 = new HashMap<>();
        data1.put("area", "Roseville Chase"); // 悉尼北岸低成交量郊区
        data1.put("percentage", "2.0%");    // 2023年仅2%房产易手，房源紧俏[8](@ref)
        areaRankings.put(1, data1);

        Map<String, Object> data2 = new HashMap<>();
        data2.put("area", "Bidwill"); // 悉尼西区高性价比郊区
        data2.put("percentage", "1.2%");    // 2023年全市成交量最低的郊区之一[8](@ref)
        areaRankings.put(2, data2);

        Map<String, Object> data3 = new HashMap<>();
        data3.put("area", "Parramatta CBD"); // 悉尼新兴高层住宅区
        data3.put("percentage", "1.8%");    // 推断占比：2024年公寓交易量最大（近700套）[6](@ref)
        areaRankings.put(3, data3);

        Map<String, Object> data4 = new HashMap<>();
        data4.put("area", "Bankstown"); // 悉尼另一个公寓交易热点
        data4.put("percentage", "1.7%");    // 推断占比：公寓交易量超500套[6](@ref)
        areaRankings.put(4, data4);

        Map<String, Object> data5 = new HashMap<>();
        data5.put("area", "Hampton East"); // 墨尔本最受关注郊区
        data5.put("percentage", "1.5%");    // 推断占比：因电视节目和可负担性成为焦点[1](@ref)
        areaRankings.put(5, data5);

        Map<String, Object> data6 = new HashMap<>();
        data6.put("area", "Bedfordale"); // 珀斯最受关注郊区
        data6.put("percentage", "1.4%");    // 推断占比：以自然环境和乡村生活吸引买家[1](@ref)
        areaRankings.put(6, data6);
;
        return AjaxResult.success("success", areaRankings);
    }

    @GetMapping("/getTrendsInRentalAmounts")
    public AjaxResult getTrendsInRentalAmounts(Map<String, Object> paramData) {
        Map<Integer, Integer> transactions = new HashMap<>();

        // 根据图表数据添加交易趋势点
        transactions.put(1120, 25);   // 1k: 25%
        transactions.put(2910, 30);   // 2k: 30%
        transactions.put(3840, 35);   // 3k: 35%
        transactions.put(4740, 40);   // 4k: 40%
        transactions.put(5620, 45);   // 5k: 45%
        transactions.put(6560, 50);   // 6k: 50%
        transactions.put(7470, 55);   // 7k: 55%
        transactions.put(8220, 60);   // 8k: 60%
        transactions.put(9120, 65);   // 9k: 65%
        transactions.put(10600, 70);  // 10k: 70% (峰值)
        transactions.put(11100, 65);  // 11k: 65%
        transactions.put(12210, 65);  // 12k: 65%
        return AjaxResult.success("success", transactions);
    }

    @GetMapping("/getTrendsInTransactionAmounts")
    public AjaxResult getTrendsInTransactionAmounts(Map<String, Object> paramData) {
        SysUser sysUser = new SysUser();
        List<String> emailList = userMapper.selectUserList(sysUser).stream().map(SysUser::getEmail).collect(Collectors.toList());
        List<Map<String, Object>> trendsInTransactionAmounts =  dataEnquiriesServiceImpl.getTrendsInTransactionAmounts(paramData,emailList);
        return AjaxResult.success("success", trendsInTransactionAmounts);
    }

    @GetMapping("/getDataView")
    public AjaxResult getDataView(HomeSaleDataView homeSaleDataVo) {
        startPage();
        Page<HomeSaleDataView> dataViewPageList = dataListingsServiceImpl.getDataView(homeSaleDataVo);
        return AjaxResult.success("查询成功", getDataTable(dataViewPageList));
    }

}
